<?php
namespace Wap\Controller;
use Think\Controller;

class UcenterController extends CommonController {	
	
	public function index(){
		$userid = session('userid');
		$userzhanghu = M('user_zhanghu')->where(array('userid' => $userid, ))->find(); //$userzhanghu = M('user_zhanghu')->where("userid=$userid")->find();
		$jiazunum = M('user_list')->where(array('utid' => $userid, ))->count(); //$jiazunum = M('user_list')->where("utid=$userid")->count();
        $username = M('user_list')->where(array('userid' => $userid, ))->find(); //$userzhanghu = M('user_zhanghu')->where("userid=$userid")->find();
		$this->jiazunum = $jiazunum;
		$this->userzhanghu = $userzhanghu;
		$this->money = $userzhanghu['uqianchong']/100;	      
        $this->uickname = $username['uickname'];
		$this->display();
	}
	public function ercode()
    {
		$userid = session('userid');
      	$ercode = M('user_erweima')->where(array('userid' => $userid, ))->find(); 
      	$url =$ercode['url'];
      	$this->url = $url;
    	$this->display();
    }    
  	public function ercodeup()
    {
		
    	$this->display();
    }
    public function ercodeupload()
    {
      			$userid = session('userid');
      			if ((($_FILES["photo"]["type"] == "image/gif")
                || ($_FILES["photo"]["type"] == "image/jpeg")
                || ($_FILES["photo"]["type"] == "image/png"))
                && ($_FILES["photo"]["size"] < 100000))
                  {
                  if ($_FILES["photo"]["error"] > 0)
                    {
                    echo "Return Code: " . $_FILES["photo"]["error"] . "<br />";
                    }
                  else
                    {
                   
						 $_FILES["photo"]["name"] = $userid.time().$_FILES["photo"]["name"];
                    if (file_exists("./Uploads/ercode/" . $_FILES["photo"]["name"]))
                      {
                      echo $_FILES["photo"]["name"] . " already exists. ";
                      }
                    else
                      {
                      			move_uploaded_file($_FILES["photo"]["tmp_name"],"./Uploads/ercode/" . $_FILES["photo"]["name"]);
                      		  
                      	 
                      			$user_erweima = M("user_erweima"); // 实例化User对象
                                $data['userid'] = $userid;
                                $data['url'] = '/Uploads/ercode/'.$_FILES["photo"]["name"];
                      			$data['ttime'] = time();
                                $res = $user_erweima->add($data);
                      			if( $res){
                                	echo "上传成功！";
                                    header("location:/index.php?m=Wap&c=Ucenter&a=ercode");
                                }
                          
                      }
                    }
                  }
                else
                  {
                  		echo "Invalid file";
                  }
        	
    }
    public function ercochange()
    {
      			
      			$userid = session('userid');
      			if ((($_FILES["photo"]["type"] == "image/gif") || ($_FILES["photo"]["type"] == "image/jpeg") || ($_FILES["photo"]["type"] == "image/png")) && ($_FILES["photo"]["size"] < 100000))
                  {
                  if ($_FILES["photo"]["error"] > 0)
                    {
                    echo "Return Code: " . $_FILES["photo"]["error"] . "<br />";
                    }
                  else
                    {
                   
						 $_FILES["photo"]["name"] = $userid.time().$_FILES["photo"]["name"];
                    if (file_exists("./Uploads/ercode/" . $_FILES["photo"]["name"]))
                      {
                      echo $_FILES["photo"]["name"] . " already exists. ";
                      }
                    else
                      {
                      			move_uploaded_file($_FILES["photo"]["tmp_name"],"./Uploads/ercode/" . $_FILES["photo"]["name"]);
                      		  
                      	 
                      			$user_erweima = M("user_erweima"); // 实例化User对象
                              
                                $data['url'] = '/Uploads/ercode/'.$_FILES["photo"]["name"];
                      			$data['ttime'] = time();
                                $res = $user_erweima->where('userid = "'.$userid.'"')->save($data);
                      			if( $res){
                                	echo "更换成功！";
                                  	header("location:/index.php?m=Wap&c=Ucenter&a=ercode");
                                }
                          
                      }
                    }
                  }
                else
                  {
                  		echo "Invalid file";
                  }
        	
    }
}
?>